import { encode, decode } from './base64'
import { KEY } from '@config'

export default {
    //以下命名为了照顾易起云那边
    key: {
        LOCK: 'LOCK',
        
        ACCESS_TOKEN: 'ACCESS_TOKEN', //token
        USER_INFO: 'USER_INFO', //user
        PERMISSION: 'PERMISSION', //权限路由

        ROUTERS: 'ROUTERS', //原始路由数据
        SIDEBAR_STATUS: "SIDEBAR_STATUS"
    },
    set(key, value, isSession) {
        let data = value ? JSON.stringify(value) : ''
        if (process.env.NODE_ENV === 'production') {
            data = encode(data)
        }
        let storage = isSession ? sessionStorage : localStorage;
        storage.setItem(KEY + '_' + key, data)
    },
    get(key, isSession) {
        let storage = isSession ? sessionStorage : localStorage;
        let data = storage.getItem(KEY + '_' + key)
        if (!data) return null
        if (process.env.NODE_ENV === 'production') {
            data = decode(data)
        }
        return (data && data !== 'undefined') ? JSON.parse(data) : null
    },
    remove(key, isSession) {
        let storage = isSession ? sessionStorage : localStorage;
        storage.removeItem(KEY + '_' + key)
    }
}

// export const cookies = {
//     // cookies设置token
//     getToken() {
//         return Cookies.get('token')
//     },
//     setToken(val) {
//         Cookies.set('token', val)
//     }
// }